<form id="form1" name="form1" method="post" action="<?php echo Url::base(); ?>index.php/user/forgetUser">
<!--内容开始-->
<div class="password-con">

    <div class="psw psw2">
        <p class="psw-p1">手机号</p>
        <input type="text" id="phone" name="phone"  onblur="checkPhone()"  placeholder="请输入手机" />
        <button onclick="sendMsg()"  type="button" id="send">获取短信验证码</button>
    </div>
    <div class="psw">
        <p class="psw-p1">验证码</p>
        <input type="text" name="code" id="code" placeholder="请输入手机验证码" />
    </div>
    <div class="psw">
        <p class="psw-p1">输入密码</p>
        <input type="password" name="password"  value="<?php echo getParmByKey('password') ?>" id="password" placeholder="请输入密码" onblur="checkpassword()" />

    </div>
    <div class="psw">
        <p class="psw-p1">确认密码</p>
        <input type="password" id="confimpassword"  value="<?php echo getParmByKey('password') ?>" placeholder="请再次确认密码"  onblur="checkconfimpassword()" />
    </div>
    <button class="psw-btn"  type="button" onclick="check()" >找回密码</button>
</div>

</form>
<script>
    <?php if(isset($msg)){ echo 'alert("'.$msg.'");';} ?>
    var url = '<?php echo Url::base(); ?>';
    function check(){
        $("#phonespan").remove()
        var phone =$("#phone").val();
        flag = true;
        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {
            flag = false;

            $("#phone").after(' <span id="phonespan" class="cuo">手机号不正确</span>')
        }else{
            $("#phone").after(' <span id="phonespan" class="dui"></span>')
        }

        $("#codespan").remove()
        if($("#code").val()=="")
        {
            flag = false;

            $("#code").after(' <span id="codespan" class="cuo">手机验证码不正确</span>')
        }else
            $("#code").after(' <span id="codespan" class="dui"></span>')

        var password = $("#password").val()
        var reg=/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i;
        $("#passspan").remove()
        if(password ==""){
            flag = false;

            $("#password").after(' <span id="passspan" class="cuo">密码不能为空</span>')
        }else if(!reg.test(password)){
            flag = false;

            $("#password").after(' <span id="passspan" class="cuo">密码由6-16的字母、数字、符号组成</span>')
        }else{
            $("#password").after(' <span id="passspan" class="dui"></span>')
        }


        $("#confimpasswordspan").remove()
        var cpassword = $("#confimpassword").val()
        if(cpassword  ==""){
            flag = false;

            $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">密码不能为空</span>')
        }else{
            $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            $("#confimpasswordspan").remove()
            if(cpassword  !=password){
                flag = false;

                $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">密码不一致</span>')
            }else{
                $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            }
        }
        if(flag)
        document.form1.submit()
    }

    function checkpassword(){
        $("#passspan").remove()
        var msg = "";
        var password = $("#password").val()
        if(password ==""){
            return false;
        }
        var reg=/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i;

        if(password.length <6||!reg.test(password)){
            msg='密码由6-16的字母、数字、符号组成'
        }
        console.log(msg)

        if(msg == ""){

            $("#password").after(' <span id="passspan" class="dui"></span>')
            return true
        }else{
            $("#password").after(' <span id="passspan" class="cuo">'+msg+'</span>')
            return false;
        }


    }
    function checkconfimpassword(){

        $("#confimpasswordspan").remove()
        var msg = "";
        var password = $("#confimpassword").val()
        if(password  ==""){
            return false;
        }
        if(password !=$("#password").val()){
            msg= "密码不一致"
        }
        if(msg == ""){

            $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            return true
        }else{
            $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">'+msg+'</span>')
            return false;
        }


    }
    var count = 60;
    var timename = null;
    var control = true;
    function sendMsg(){
        if(control){
            control=false;

            if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
            {
                control=true;
                alert('请输入正确手机号');
                return;
            }

            $.ajax({

                type: 'get',

                url:  url+'index.php/user/sendForgetPassword',

                data: {phone:$("#phone").val()} ,

                success: function(data){
                    if(data.msg ){
                        timename=setInterval(function() {
                            if(count == 0){
                                count = 60;
                                control= true;
                                $("#send").html("获取短信验证码")

                                clearInterval(timename)
                                return;
                            }
                            $("#send").html(count+"后重新发送")

                            count --;
                        },1000);
                    }else{
                        control=true;
                        alert(data.data)
                    }
                },

                dataType: 'json'

            });
        }
    }
    function checkPhone(){
        $("#phonespan").remove()
        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {


            $("#phone").after(' <span id="phonespan" class="cuo">手机号不正确</span>')
        }else{
            $("#phone").after(' <span id="phonespan" class="dui"></span>')
        }
    }
</script>